home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / TCP_IP / TNOS230S / HELP.C < prev    next >
C/C++ Source or Header  |  1997-08-18  |  3KB  |  154 lines

  1. /* Help engine:
  2.  *
  3.  * Copyright 1993 Brian A. Lantz, KO4KS
  4.  */
  5. #include "global.h"
  6. #include "cmdparse.h"
  7. #include "help.h"
  8. #include "files.h"
  9. #include "socket.h"
  10.  
  11. #if !defined(_lint)
  12. static char rcsid[] OPTIONAL = "$Id: help.c,v 1.17 1997/08/19 01:19:22 root Exp root $";
  13. #endif
  14.  
  15. extern struct cmds Mbcmds[];
  16. extern struct cmds Cmds[];
  17.  
  18. static int ours (const char *buf, const char *search);
  19.  
  20.  
  21. static int
  22. ours (buf, search)
  23. const char *buf, *search;
  24. {
  25. char buf2[82], search2[82];
  26.  
  27.     if (strchr (buf, '*'))
  28.         return ((search == NULLCHAR) ? 1 : 0);
  29.     if (search == NULLCHAR)
  30.         return 1;
  31.     strncpy (buf2, buf, 82);
  32.     strncpy (&search2[1], search, 81);
  33.     search2[0] = ':';
  34.     (void) strlwr (buf2);
  35.     (void) strlwr (search2);
  36.     return ((int)strstr (buf2, search2));
  37. }
  38.  
  39.  
  40. void
  41. dohelper(title,cmdp,stopstr,filename,search)
  42. const char *title, *stopstr, *search, *filename;
  43. register struct cmds *cmdp;
  44. {
  45. int i;
  46. char buf[82];
  47. struct cmds *saved;
  48. int width = 0, count;
  49. FILE *fp;
  50.  
  51.     saved = cmdp;
  52.     for ( ; cmdp && cmdp->name != NULL; cmdp++)
  53.         width = ((int)strlen(cmdp->name) > width) ? (int) strlen(cmdp->name) : width;
  54.     width += 1;
  55.     count = (79 / width);
  56.     cmdp = saved;
  57.     if (title && (filename == NULLCHAR || search == NULLCHAR))
  58.         tputs(title);
  59.     if (filename == NULLCHAR)    {    /* '?' commands    */
  60.         tputs (" ");
  61.         memset(buf,' ',sizeof(buf));
  62.         buf[77] = '\n';
  63.         buf[78] = '\0';
  64.         for(i=0;cmdp->name != NULL;cmdp++,i = ((i+1) % count)){
  65.             if (stopstr && !stricmp (cmdp->name, stopstr))
  66.                 break;
  67.             strncpy(&buf[i * width],cmdp->name,strlen(cmdp->name));
  68.             if(i == (count - 1)){
  69.                 tprintf("%s ", buf);
  70.                 memset(buf,' ',77);
  71.             }
  72.         }
  73.         if(i != 0)
  74.             tputs(buf);
  75.         else
  76.             tputc ('\b');
  77.         return;
  78.     }
  79.     if ((fp = fopen (filename, READ_TEXT)) != NULLFILE)    {
  80.         if ((search != NULLCHAR) && cmdp)
  81.             tputs ("Usage:\n");
  82.         count = 0;
  83.         do    {
  84.             if (fgets (buf, 80, fp))    {
  85.                 if (*buf == '#')
  86.                     continue;    /* skip comments    */
  87.                 if (*buf != ':')    {
  88.                     if (count)    {
  89.                         count--;
  90. /*                        if (search != NULLCHAR)
  91.                             tputs ("  ");
  92.                         tputs (buf);        */
  93.                         tprintf ("  %s", buf);
  94.                     }
  95.                 } else    {    /* start of field or continuation */
  96.                     count = (ours (buf, search)) ? 32000 : 0;
  97.                     if (search == NULLCHAR && count)
  98.                         count = 1;
  99.                     if (buf[1] == ':' && count == 1)
  100.                         count--;
  101.                 }
  102.             }
  103.         } while (!feof (fp));
  104.         (void) fclose (fp);
  105.     }
  106. }
  107.  
  108. int
  109. dohelp(argc, argv, p)
  110. int argc;
  111. char *argv[];
  112. void *p OPTIONAL;
  113. {
  114.     dohelper ("Main commands:\n", &Cmds[1], "a:", (argv[0][0] == '?' && argc == 1) ? NULLCHAR : CommandHelp, (argc == 2) ? argv[1] : NULLCHAR);
  115.     return 0;
  116. }
  117.  
  118.  
  119. #if 0
  120. int
  121. syntax(cmd)
  122. char *cmd;
  123. {
  124.     dohelper (NULLCHAR, &Cmds[1], "a:", CommandHelp, cmd);
  125.     return 0;
  126. }
  127. #endif
  128.  
  129. int
  130. dombxhelp(argc, argv, p)
  131. int argc;
  132. char *argv[];
  133. void *p OPTIONAL;
  134. {
  135. char buf[255];
  136.  
  137.     sprintf (buf, "Mailbox Commands for %s at %s\n\n", Version, Hostname);
  138.     dohelper (buf, &Mbcmds[1], "[", (argv[0][0] == '?' && argc == 1) ? NULLCHAR : PBBSHelp, (argc == 2) ? argv[1] : NULLCHAR);
  139.     return 0;
  140. }
  141.  
  142.  
  143. #if 0
  144. int
  145. mbxsyntax(cmd)
  146. char *cmd;
  147. {
  148.     dohelper (NULLCHAR, &Mbcmds[1], "[", PBBSHelp, cmd);
  149.     return 0;
  150. }
  151. #endif
  152.  
  153.  
  154.